import { request } from './request'
import type { Product, PaginatedResponse } from '@/types'

// 获取产品列表
export const getProducts = (params: {
  page: number
  page_size: number
  category_id?: number
  status?: number
}) => {
  return request<PaginatedResponse<Product>>({
    url: '/admin/products',
    method: 'get',
    params
  })
}

// 获取产品详情
export const getProduct = (id: number) => {
  return request<Product>({
    url: `/admin/products/${id}`,
    method: 'get'
  })
}

// 创建产品
export const createProduct = (data: Partial<Product>) => {
  return request<Product>({
    url: '/admin/products',
    method: 'post',
    data
  })
}

// 更新产品
export const updateProduct = (id: number, data: Partial<Product>) => {
  return request<Product>({
    url: `/admin/products/${id}`,
    method: 'put',
    data
  })
}

// 删除产品
export const deleteProduct = (id: number) => {
  return request({
    url: `/admin/products/${id}`,
    method: 'delete'
  })
}

